package com.tengju.payment.infrastructure.repository.channel;

import com.tengju.payment.domain.model.BusinessType;
import com.tengju.payment.domain.model.ChannelType;
import com.tengju.payment.domain.model.channel.Channel;
import com.tengju.payment.domain.model.channel.ChannelId;
import com.tengju.payment.domain.model.channel.ChannelRepository;
import com.tengju.payment.infrastructure.persistence.mybatis.dataobject.ChannelDO;
import com.tengju.payment.infrastructure.persistence.mybatis.mapper.ChannelMapper;
import com.tengju.payment.infrastructure.repository.convert.RepositoryChannelConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

//渠道数仓服务
@Repository("channelRepository")
public class ChannelRepositoryImpl implements ChannelRepository {

    @Resource
    private ChannelMapper channelMapper;

    @Override
    public void save(Channel channel) {

        ChannelDO channelDO = RepositoryChannelConvert.domainToDo(channel);

        channelMapper.insert(channelDO);

    }


    @Override
    public Channel findByBusinessChannelType(BusinessType businessType, ChannelType channelType) {

        ChannelDO channelDO = channelMapper.getByBusinessChannelType(businessType.getVal(), channelType.getVal());


        return RepositoryChannelConvert.doToDomain(channelDO);
    }

    @Override
    public Channel findByChannelId(ChannelId channelId) {
        ChannelDO channelDO = channelMapper.getById(channelId.getValue());


        return RepositoryChannelConvert.doToDomain(channelDO);
    }
}
